<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content">
				<view class="order-item" v-for="(item,index) in orderList" :key='index'
					@tap="goOrderDetails(item.order_no)" v-if="index==0">
					<view class="item-top">
						<view class="table-info flexWrapNo">
							<view class="big">{{numText}}</view>
							<view class="info">
								<view class="table-name flexWrapNo">
									{{characters}}
									<view class="residue flexWrapNo" v-if="item.order_status==10"> 
										<view class="order-status">
											使用中
										</view>
										<liu-countdown ref="countdown3" auto mode="2" :showDays="false" :endDate="item.service_end_time"></liu-countdown>
									</view>
									<view class="order-status"  style="margin-left: 12upx;"  v-else :class="{'end':item.order_status==20||item.order_status==30,'noStarted':item.order_status==0}">
										<block v-if="item.order_status==0">待使用</block>
										<block v-if="item.order_status==20">已结束</block>
										<block v-if="item.order_status==30">已取消</block>
										<block v-if="item.order_status==40">已超时</block>
									</view>
								</view>
								<view class="store-name flexWrapNo">
									<image src="/static/home/navigation-icon.png" class="navigation-icon"></image>
									{{shop_name}}
								</view>
							</view>
						</view>
						<view class="order-info flexWarpColumn">
							<view class="order-text-box">
								<view class="order-text">
									<text>订单时间：</text>
									{{item.service_date}} {{item.start_time}}～
									<block v-if="item.is_ci==1">次日</block> {{item.end_time}}
								</view>
								<view class="order-text">
									<text>下单时间：</text>{{item.createtime}}
								</view>
								<view class="order-text">
									<text>实&nbsp;付&nbsp;款：</text>￥{{item.actual_payment}}
								</view>
							</view>
							<view class="flexWrap">
								<view class="order-btn">结束订单</view>
								<view class="order-btn renew" @tap.stop="goRenew(item)">续费</view>
								<view class="order-btn">+状态</view>
							</view>
						</view>
					</view>
				</view>
				<view class="open-box flexWrap">
					<view class="open-item" @tap="openBigDoor()" v-if="shop_name&&orderList.length!=0">
						<view class="name">大门</view>
						<view class="operation-box flexWrap">
							<view class="open-btn flexWarpColumn">
								<text>开门</text>
							</view>
							<!-- <view class="operation-img">
								<image src="../../static/home/open.png"></image>
							</view> -->
						</view>
					</view>
					<view class="open-item" v-for="(item,index) in orderList" :key="index" @tap="openRoomDoor(item.store_equipment_id)">
						<view class="name">{{item.store_equipment_name}}</view>
						<view class="operation-box flexWrap">
							<view class="open-btn flexWarpColumn">
								<text>开门</text>
							</view>
							<!-- <view class="operation-img">
								<image src="../../static/home/open.png"></image>
							</view> -->
						</view>
					</view>
				</view>
				<view class="empty-box flexWarpCenterColumn" v-if="orderList.length==0">
					<image src="/static/empty-img.png" class="empty-image"></image>
					<view class="empty-tips">暂无订单</view>
				</view>
				<view class="service-box flexWrapNo" @tap="makePhoneCall">
					<image src="../static/user/service.png" class="service-icon"></image>
					{{phoneNumber}}
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageOpc: 0,
				doorInfo:{
					shop_name:""
				},
				orderList:[],
				store_id:"",
				damen:"",
				token:"",
				shop_name:"",
				numText:"",
				characters:"",
				phoneNumber:""
			};
		},
		onReady() {
			setTimeout(() => {
				this.pageOpc = 1
			}, 100)
		},
		onLoad(ops) {
			this.store_id=ops.store_id||uni.getStorageSync('store_id')
			this.token=ops.token||uni.getStorageSync('token')
			this.store_equipment_id=ops.store_equipment_id
			this.getDoorList();
		},
		methods:{
			goRenew(item) {
				uni.navigateTo({
					url: "/moduleA/beforConfirm?equipment_id=" + item.store_equipment_id + '&renew_order_id=' + item.id+'&order_type=immediately'
				})
			},
			goOrderDetails(order_no) {
				uni.navigateTo({
					url: "/moduleA/orderDetails?order_no=" + order_no
				})
			},
			// 获取包房信息
			getDoorList(){
				this.$request.post(this.$api.doorList, {
					store_id:this.store_id,
					token:this.token
				}, {}).then(res => {
					if (res.code==1) {
						let {
							data = {}
						} = res;
						let newArray = data.order
						if(newArray.length!=0){
							for (let i in newArray) {
								newArray[i].createtime = this.$tools.formatDate(newArray[i].createtime, 1)
								newArray[i].service_start_time = this.$tools.formatDate(newArray[i].service_start_time,
									0)
								newArray[i].service_end_time = this.$tools.formatDate(newArray[i].service_end_time, 0)
								newArray[i].service_date = newArray[i].service_start_time.split(' ')[0]
								newArray[i].start_time = newArray[i].service_start_time.split(' ')[1]
								newArray[i].end_time = newArray[i].service_end_time.split(' ')[1]
							}
							this.doorInfo={
								equipment_name:newArray[0].store_equipment_name,
								shop_name:data.damen.shop_name||"",
								service_date:newArray[0].service_date,
								start_time:newArray[0].start_time,
								end_time:newArray[0].end_time
							}
							this.orderList=newArray
							this.numText=""
							this.characters=""
							let nameList=this.doorInfo.equipment_name.split('')
							let isNaNEmpty = false //是否有数字
							isNaNEmpty =nameList.some(item =>!isNaN(item))
							if(!isNaNEmpty||isNaN(nameList[0])){
								for(let i in nameList){
									if(i==0){
										this.numText+=nameList[i]
									}else{
										this.characters+=nameList[i]
									}
								}
							}else{
								for(let i in nameList){
									if(!isNaN(nameList[i])){
										this.numText+=nameList[i]
									}else{
										this.characters+=nameList[i]
									}
								}
							}
						}
						if(data.damen.shop_name){
							this.shop_name=data.damen.shop_name
							this.phoneNumber=data.damen.customer_service_mobile
						}
					}
				})
			},
			// 拨打电话
			makePhoneCall() {
				let that = this
				if(!that.phoneNumber){
					this.$tools.showToast('暂无客服电话')
					return;
				}
				uni.makePhoneCall({
					phoneNumber:that.phoneNumber
				})
			},
			// 开大门
			openBigDoor(){
				uni.showLoading({
					title:'开门中，请稍等',
					mask:true
				})
				this.$request.post(this.$api.openBigDoor, {
					store_id:this.store_id,
					token:this.token
				}, {}).then(res => {
					if (res.code==1) {
						this.$tools.hideLoading()
						this.$tools.showToast('开门成功')
					}
				}).finally(() => {
					setTimeout(()=>{
						this.$tools.hideLoading()
					}, 1000)
				})
			},
			// 开包房门
			openRoomDoor(store_equipment_id){
				uni.showLoading({
					title:'开门中，请稍等',
					mask:true
				})
				this.$request.post(this.$api.openRoomDoor, {
					store_id:this.store_id,
					store_equipment_id:store_equipment_id,
					token:this.token
				}, {}).then(res => {
					if (res.code==1) {
						this.$tools.hideLoading()
						this.$tools.showToast('开门成功')
					}
				}).finally(() => {
					setTimeout(()=>{
						this.$tools.hideLoading()
					}, 1000)
				})
			}
		}
	}
</script>

<style lang="scss">
	.content{
		padding: 30upx;
	}
	.order-item {
		min-height: 364upx;
		background: #232428;
		border-radius: 16upx;
		padding-top: 36upx;
		margin-bottom: 20upx;
		position: relative;
	
		.item-top {
			min-height: 304upx;
			align-items: self-start;
			.table-info {
				padding:0 32upx;
				.big {
					font-family: Arial, Arial;
					font-weight: bold;
					font-size: 136rpx;
					color: #F9FAFE;
				}
			
				.info {
					margin-left: 20upx;
			
					.table-name {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 34rpx;
						color: #F9FAFE;
			
						text {
							font-size: 32upx;
						}
					}
			
					.store-name {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 30rpx;
						color: #FFFFFF;
						margin-top: 20upx;
						opacity: .6;
			
						.navigation-icon {
							width: 26upx;
							height: 34upx;
							margin-right: 10upx;
						}
					}
				}
			}
			.order-status {
				width: 118upx;
				height: 48upx;
				background: linear-gradient( 180deg, #4AA22A 0%, #69D037 100%);
				border-radius:48upx;
				font-size: 24upx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 48upx;
				color: #FFFFFF;
				text-align: center;
				margin-right: 12upx;
			}
			.residue{
				min-width: 234rpx;
				height: 48rpx;
				background: #464F58;
				border-radius: 48rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				line-height: 48upx;
				font-size: 26rpx !important;
				color: #A3A7AC;
				margin-left: 10upx;
				padding-right: 20upx;
			}
			.noStarted{
				background: #7781FD;
			}
			.end{
				background: #848C95;
			}
			.order-info {
				padding:0 32upx;
				min-height: 304upx;
				padding-bottom: 10rpx;
				flex: 1;
				.shop-name {
					font-size: 30upx;
					font-family: PingFang SC;
					font-weight: 400;
					line-height: 34upx;
					color: #999999;
					margin-top: 16upx;
				}
				.order-text-box{
					margin-top: 20upx;
					.order-text {
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 400;
						line-height: 34upx;
						color: #FFFFFF;
						margin-bottom: 16upx;
						text{
							color: #919294;
							display: inline-block;
							width: 130upx;
						}
					}
				}
				.order-btn {
					width: 200upx;
					height: 96upx;
					line-height: 96upx;
					text-align: center;
					border: 2upx solid rgba(255, 255, 255, .5);
					border-radius: 48upx;
					font-size: 32upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					margin-top: 26upx;
				}
				.renew{
					background: linear-gradient( 90deg, #4AA22A 0%, #69D037 100%);
					border: none;
				}
			}
	
			.order-img {
				width: 304upx;
				height: 304upx;
				flex: none;
			}
		}
		
		.open-box{
			padding: 30rpx;
			padding-top: 0;
			.open-btn{
				width: 304rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				border: 2upx solid rgba(255, 255, 255, .5);
				border-radius: 48upx;
				font-size: 36upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}
			.share{
				background: #343940;
				width: 304rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				border: 2rpx solid #343940;
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				border-radius: 48upx;
			}
		}
		.item-bottom {
			height: 60upx;
			background: #353484;
			border-radius: 0px 0px 16upx 16upx;
			font-size: 24upx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 60upx;
			color: #999999;
			padding: 0 28upx;
	
			.icon-more {
				border-color: #969696;
				width: 12upx;
				height: 13upx;
				margin-left: 10upx;
			}
		}
	
	}
	.open-box{
		margin-top: 36rpx;
		flex-wrap: wrap;
		.open-item{
			width: 264rpx;
			height: 192rpx;
			background:#232428;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			padding: 28rpx;
			margin-bottom: 30rpx;
			.name{
				font-size: 36rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}
			.operation-box{
				margin-top: 40rpx;
				justify-content: flex-end;
				.open-btn{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFF;
					width: 205rpx;
					height: 86rpx;
					line-height: 86rpx;
					text-align: center;
					background: linear-gradient( 90deg, #4AA22A 0%, #69D037 100%);
					border-radius: 48rpx;
				}
				.operation-img{
					width: 134rpx;
					height: 190rpx;
					flex: none;
				}
			}
		}
	}
	.service-box{
		font-family: PingFang SC, PingFang SC;
		font-weight: 600;
		font-size: 34rpx;
		color: #FFFFFF;
		width: 414rpx;
		height: 96rpx;
		background: #232428;
		border-radius: 72rpx;
		margin: auto;
		margin-top: 30upx;
		.service-icon{
			width: 96upx;
			height: 96upx;
			margin-right: 20upx;
		}
	}
</style>
